package wypozyczalnia.dao;

import java.util.Calendar;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import wypozyczalnia.domain.Hire;
import wypozyczalnia.domain.User;

@Repository
public class HireDao extends GenericDao<Hire> {

	@Autowired
	public HireDao(SessionFactory sf) {
		super(Hire.class, sf);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Hire> getAll() {
		return getHibernateTemplate().find("from Hire");
	}

	@SuppressWarnings("unchecked")
	public List<Hire> getHiresForRaport() {
		Calendar cal = Calendar.getInstance();
		int month = cal.get(Calendar.MONTH) + 1;
		return getHibernateTemplate().find(
				"from Hire hire where MONTH(hire.startDate)=?", month);
	}

	@SuppressWarnings("unchecked")
	public List<Hire> getHiresForUser(User user) {
		List<Hire> hired = getHibernateTemplate().find(
				"from Hire hire where hire.user=?", user);
		return hired;

	}
}
